package cn.tedu.csmall.passport.controller;

import cn.tedu.csmall.passport.pojo.vo.RoleListItemVO;
import cn.tedu.csmall.passport.service.IRoleService;
import cn.tedu.csmall.passport.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags = "角色模块")
@RestController
@RequestMapping("/roles")
@Validated
public class RoleController {

    @Autowired
    private IRoleService service;

    @GetMapping("")
    @ApiOperation("查看角色列表")
    @ApiOperationSupport(order = 200)
    public JsonResult<List<RoleListItemVO>> list(){
        log.debug("开始处理查看角色列表请求");
        List<RoleListItemVO> list = service.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("重建品牌缓存")
    @ApiOperationSupport(order = 600)
    @PostMapping("/cache/rebuild")
    public JsonResult<Void> rebuildCache(){
        log.debug("开始处理重建品牌缓存请求");
        service.rebuildCache();
        return JsonResult.ok();
    }
}

